package com.zyk.plugin.costtime;

import net.bytebuddy.asm.Advice;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CostTimeAdvice {
    public static final Logger LOGGER = LoggerFactory.getLogger(CostTimeAdvice.class);

    @Advice.OnMethodEnter(suppress = Throwable.class)
    static long enter(@Advice.Origin String origin, @Advice.AllArguments Object[] ary) {
        return System.currentTimeMillis();
    }

    @Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
    static void exit(@Advice.Enter long time, @Advice.Origin(value = "#t.#m") String origin) {
        LOGGER.debug("Method:{} Execution Time: {} ms", origin, System.currentTimeMillis() - time);
    }

}
